<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>
</head>
<body>
  <div id="myDiv">
      <script src="./plugins/vue/dist/vue.min.js"></script>
      <script src="./plugins/axios/dist/axios.js"></script>
      <script src="./js/common.js"></script>
      <script type="text/javascript">
          //创建vue是需要给他传递一个对象
          new Vue({
                  el: "#myDiv", //id在hmtl模板中要对应
                  data:{},
                  methods:{
                  },
              mounted() {
                  /**通过方法获取url里的code和state并封装为key-value*/
                  var obj = parseUrlParams2Obj(location.href);
                  /**包裹code和绑定页面的url*/
                  var params = {
                      code: obj.code,
                      binderUrl: "http://bugtracker.itsource.cn/binder.html"
                  };
                  this.$http.post("/USER/wxLogin", params)
                      .then(result => {
                          let {success, message, resultObj} = result.data;//结构表达式 赋值
                          if (success) {
                              //登录成功 存放token和用户到localstorage
                              localStorage.setItem("uToken", resultObj.uToken)
                              localStorage.setItem("user", resultObj.user)
                              //跳转主页
                              location.href = "/index.html"
                              return;
                          }
                          if ("binder" === message) {
                              //跳转到绑定页面  ？ message有code这些
                              location.href = resultObj;
                          }
                      });
              }
          })
       </script>
  </div>
</body>
</html>